package com.glory.dmegcpda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.glory.dmegcpda.R;
import com.glory.dmegcpda.utils.BitmapUtil;
import com.glory.dmegcpda.utils.VideoModel;

import java.util.List;

public class LookPDFAdapter extends BaseAdapter {
    private Context ct ;
    private List<VideoModel> list;

    public LookPDFAdapter(Context c, List<VideoModel> mList) {
        super();
        this.ct = c;
        this.list = mList;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VH vh ;
        if(convertView==null){
            convertView = LayoutInflater.from(ct).inflate(R.layout.item_pdf_list, null);
            vh = new VH();
            vh.tv_name = (TextView) convertView
                    .findViewById(R.id.tv_name_pdf_list);
            vh.tv_time = (TextView) convertView
                    .findViewById(R.id.tv_time_pdf_list);
            vh.iv = (ImageView) convertView
                    .findViewById(R.id.iv_pdf_list);
            vh.tv_length = (TextView) convertView
                    .findViewById(R.id.tv_length_pdf_list);
            vh.tv_last=convertView.findViewById(R.id.ac_adapter_tv_last);
            convertView.setTag(vh);
        }else{
            vh = (VH) convertView.getTag();
        }
        vh.tv_name.setText(list.get(position).getName());
        String path = list.get(position).getPath();
        vh.tv_time.setText(BitmapUtil.getFileCreatedTime(path));
        vh.tv_length.setText(BitmapUtil.getVideoLength(path));
        if(position==0){
            vh.tv_last.setVisibility(View.VISIBLE);
        }else{
            vh.tv_last.setVisibility(View.GONE);
        }

        return convertView;
    }

    class VH {
        ImageView iv;
        TextView tv_name,tv_time,tv_length,tv_last;
    }


}
